package database;

import java.util.LinkedList;

import recipie.core.Ingredient;
import recipie.core.IngredientCollection;
import recipie.core.Recipe;
import recipie.core.RecipeCollection;

import category.Category;
import category.CategoryCollection;

public class Repository 
{
/***************************CATEGORIES**********************************************************************/	
	/*Insert single a category, that can be of 2 kinds:
	 * -leaf category: it has a father and no sub-categories.
	 * -upper category: it has a father and one level of sub-categories (for inserting
	 * a new category not at leaves level).*/
	public static boolean insertCategory(Category category)
	{
	  return CategoryManager.insertCategory(category);
	}
	
	//Insert an ordered list of categories (breadth first order).
	public static boolean insertCategories(LinkedList<Category> categories)
	{
	  for(Category c : categories)
	    if(!CategoryManager.insertCategory(c))
	      return false;
	  
	  return true;
	}
	
	//Delete a category
	public static boolean deleteCategory(Category category)
	{
	  return CategoryManager.deleteCategory(category);
	}
	
    //Check if a category exists
	public static boolean existsCategory(String id) 
	{
	  return CategoryManager.existsCategory(id);
	}
	
	//Load all categories
	public static CategoryCollection loadCategories() 
	{
	  return CategoryManager.loadCategories();
	}
	
	//Insert a single category and update local copy
	public static CategoryCollection insertCategoryAndUpdate(Category category)
	{
	  if(CategoryManager.insertCategory(category))
	    return CategoryManager.loadCategories();
	  
	  return null;
	}
/************************************************************************************************************/

/***************************INGREDIENTS**********************************************************************/
    public static boolean insertIngredient(Ingredient ingredient)
	{
	  return IngredientManager.insertIngredient(ingredient);
	}
    
    public static boolean deleteIngredient(Ingredient ingredient)
   	{
   	  return IngredientManager.deleteIngredient(ingredient);
   	}
    
    public static boolean existsIngredient(String id) 
	{
	  return IngredientManager.existsIngredient(id);
	}
    
    public static IngredientCollection loadIngredients() 
	{
	  return IngredientManager.loadIngredients();
	}
/************************************************************************************************************/
    
/***************************RECIPES**********************************************************************/
	public static void insertRecipe(Recipe recipe) 
	{
	  RecipeManager.insertRecipe(recipe);
	}
	public static RecipeCollection loadRecipes() 
	{
	  return RecipeManager.loadRecipes();
	}

	public static boolean deleteRecipe(Recipe recipe) 
	{
	  return RecipeManager.DeleteRecipe(recipe);
	}
	
	
}
